package RockPaperScissors
{
    public class Utilities
    {
        public function Utilities()
        {
        }
        
        public static function createCallBack(fn:Function, args:*):Function
        {
            return function(event:*)
            {
                fn(event, args);
            }
        }
        
        public static function map(func:Function, list)
        {
            var ret = [];
            for(var li in list)
            {
                ret[ret.length] = func(list[li]);
            }
            return ret;
        }

        public static function reduce(func:Function, list){
            var last = new Object();
            if(list.length <= 1) return;
            if(list.length == 2) return func(list[0],list[1]);
        
            last = list[0];
            for(var li = 1;li < list.length;li++){
                last = func(last,list[li]);
            }
            return last;
        }
    }
}